package com.zhuss;


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import com.github.wxpay.sdk.WXPayConfig;
import com.zhuss.enums.IsEnum;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;

/** 配置我们自己的信息  */
public class WxCertParam implements WXPayConfig {

    /** 加载证书  这里证书需要到微信商户平台进行下载*/
    private byte [] certData;
    
    private String appId;
    
    private String mchId;
    
    private String key;

    public WxCertParam(String appId, String mchId, String key, Integer isNeedCert, String wxPayCertPath) throws DzcxException {
    	this.appId = appId;
    	this.mchId = mchId;
    	this.key = key;
        try {
        	if (IsEnum.是.sameKey(isNeedCert)) {
        		InputStream certStream = null;
        		try {
        			certStream = new FileInputStream(new File(wxPayCertPath));
        		} catch (FileNotFoundException e) {
        			e.printStackTrace();
        			throw new DzcxException(ExceptionCode.微信支付证书加载错误);
        		}
        		this.certData = new byte[certStream.available()];
        		certStream.read(this.certData);
        		certStream.close();
        	}
		} catch (Exception e) {
			e.printStackTrace();
			throw new DzcxException(ExceptionCode.微信支付证书加载错误);
		}
    }

    /** 设置我们自己的appid
     * 商户号
     * 秘钥
     * */

    @Override
    public String getAppID() {
    	return this.appId;
    }

    @Override
    public String getMchID() {
    	return this.mchId;
    }

    @Override
    public String getKey() {
    	return this.key;
    }

    @Override
    public InputStream getCertStream() {
        return new ByteArrayInputStream(this.certData);
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 0;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 0;
    }
}